home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / proff.arc / EVAL.C < prev    next >
Text File  |  1988-02-17  |  1KB  |  66 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include "proff.h"
  4. #include "debug.h"
  5.  
  6.  
  7. /*
  8.  * eval - evaluate defined command (push back definition)
  9.  *
  10.  */
  11. eval(buf,defn)
  12. char buf[];
  13. char defn[];
  14. {
  15.     register int j,k;
  16.     int i;
  17.     int argptr[10];
  18.  
  19.     for (i = 0; i < 10 ; i++)
  20.         argptr[i] = 0;
  21.  
  22.     buf[0] = '\0';        /* buf[0] is cchar */
  23.     dprintf(defn);
  24.     dprintf("eval  ");
  25.     i = 1;
  26.     argptr[0] = 1;        /* first parm is macro name */
  27.     while (buf[i] != ' ' && buf[i] != '\t' &&
  28.         buf[i] != '\n' && buf[i] != '\0')
  29.         i++;
  30.     buf[i++] = '\0';        /* EOS terminate */
  31.     /*
  32.      * start scanning remaining macro parameters.
  33.      * delimiters are blanks or commas. Any string
  34.      * enclosed with double quotes are accepted as
  35.      * parameters as well
  36.      *
  37.      */
  38.     for (j = 1; j < 10; j++) {
  39.         skipbl(buf, &i);
  40.         if (buf[i] == '\n' || buf[i] == '\0')
  41.             break;
  42.         argptr[j] = i;
  43.         while (buf[i] != ' ' && buf[i] != '\t' &&
  44.             buf[i] != ',' && buf[i] != '\n' && buf[i] != '\0')
  45.             i++;
  46.         buf[i] = '\0';
  47.         i++;
  48.     }
  49.     for (k = strlen(defn) - 1; k >= 0; k--)
  50.         if (defn[k-1] != ARGFLAG)
  51.             putbak(defn[k]);
  52.         else {
  53.             if (defn[k] < '0' || defn[k] > '9')
  54.                 putbak(defn[k]);
  55.             else {
  56.                 i = defn[k] - '0';
  57.                 i = argptr[i];
  58.                 pbstr(&buf[i]);
  59.                 k--;        /* skip over $ */
  60.             }
  61.         }
  62.     if (k == 0)    /* do the last character */
  63.         putbak(defn[k]);
  64. }
  65.  
  66.